﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace Tanks
{
    class Animation : IFieldObject
    {
        private int frameWidth;   //ширина кадра
        private int frames;       //количество кадров
        private int currentFrame; //номер текущего кадра
        private int animationTime;//время показа текущего кадра
        private int frameTime;    //скорость смены кадров
        private float zoom;
        

        public Animation(Texture2D _tex, Game1 game, Vector2 position, float rotation, int frameTime, float zoom)
            : base(game, new PropertiesObject(), _tex)
        {
            Properties.IsFon = true;
            this.rotation = rotation;
            this.position = position;
            currentFrame = 0;
            animationTime = 0;
            frameWidth = texture.Height;
            frames = texture.Width / frameWidth;
            this.frameTime = frameTime;
            this.zoom = zoom;
        }

        public override float getActualRotation()
        {
            return rotation;
        }
        public override Vector2 getActualPosition()
        {
            return position;
        }
        public override Vector2[] getActualBoards()
        {
            return null;
        }
        public override void Update(GameTime gameTime)
        {
            if (animationTime > frameTime)
            {
                if (currentFrame < frames - 1)
                {
                    currentFrame++;
                }
                else
                {
                    game.DeleteObject(this);
                }
                animationTime = 0;
            }
            else
            {
                animationTime += gameTime.ElapsedGameTime.Milliseconds;
            }
            
            
        }
        public override void Draw()
        {
            game.SpriteBatch.Draw(texture, position, new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameWidth), Color.White, rotation,
                    new Vector2(frameWidth / 2, frameWidth / 2), zoom, SpriteEffects.None, 0);                    
        }
        public override Vector2[] getBoards()
        {
            return null;
        }
        public override void collisionNotFounded()
        {
        }
        public override void collisionRotNotFounded()
        {
        }
        public override void collisionFounded(IFieldObject two)
        {            
        }
    }
}
